/*
 * @Descripttion:
 * @version: 1.0.0
 * @Author: JGY
 * @Date: 2024-04
 */
import {
  IEnvironment,
  CMEVENTS,
  contextMenuManager,
  DocumentUtils,
} from '@amcax/base';
import {
  ActionBar,
  AssistLayer,
  CommandBar,
  RightNavigation,
  TreeContextMenu,
} from './widgets';
import { ModelContextMenu } from './widgets/ContextMenu/ModelContextMenu';
import { csEvent } from '../../common/events/EventCenter';
import { ctx2, userEvents } from '../../module';

export const airfoilEnvironment: IEnvironment = {
  id: 'Airfoil',
  label: '翼型设计',
  index: 0,
  init: () => {
    console.log('Env Init Airfoil');
  },
  load: async () => {
    console.log('Env Load Airfoil');
    csEvent().setState('airfoil');
    userEvents.on(CMEVENTS.MODEL_RIGHT_CLICK, (event: PointerEvent) => {
      setTimeout(() => {
        contextMenuManager.show(event, ModelContextMenu.id);
      });
    });

    setTimeout(() => {
      if (ctx2.cadScene.edgeGroup.children.length > 0) {
        userEvents.emit('sceneEmpty', false);
      }
      ctx2.viewer.sceneSetup.fit2DView();
    }, 500);
    ctx2.viewer.sceneSetup.lock2DView();
  },
  unload: async () => {
    console.log('Env UnLoad Airfoil');
    csEvent().setDefault();
  },
  commandBar: () => {
    return <CommandBar />;
  },
  // contextMenus: () => {
  //   return [ModelContextMenu, TreeContextMenu];
  // },
  // leftPanel: () => {
  //   return <LeftPanel />
  // },
  rightNavigation: () => {
    return <RightNavigation />;
  },
  actionBar: () => {
    return DocumentUtils.isReadOnly() ? null : <ActionBar />;
  },
  assistLayer: () => {
    return <AssistLayer />;
  },
};
export default airfoilEnvironment;
